using Godot;
using System;

public partial class DashInAir : Node,StateNode
{
	public Enemy enemy;

	[Export]
	public int dashSpeed = 700;

	// Called when the node enters the scene tree for the first time.
	public override void _Ready()
	{
		enemy = GetNode<Enemy>("/root/Main/Enemy");
	}

	public void OnDash()
	{
		enemy.Velocity = (enemy.player.Position-enemy.Position).Normalized()*dashSpeed;

		enemy.enableGravity = false;

		enemy.GetNode<AudioStreamPlayer2D>("DashMusic").Play();
	}

    public void OnEnter()
    {
        OnDash();

		enemy.GetNode<AnimatedSprite2D>("AnimaEnemy").Animation = "dash_in_air";
    }

    public void OnUpdate(float delta)
    {	
        if(enemy.Health<=0)
			enemy.SwitchTo("Dead");
		else if(enemy.IsOnFloor())
		{
			enemy.SwitchTo("Idle");
		}
    }

    public void OnExit()
    {
        enemy.enableGravity = true;
		enemy.Velocity = new(0,0);
    }

}
